package com.zhuiyun.project.api.venuemanagement.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.venuemanagement.entity.BanRecord;
import com.zhuiyun.project.api.venuemanagement.entity.VenueManagement;
import com.zhuiyun.project.api.venuemanagement.mapper.VenueManagementMapper;
import com.zhuiyun.project.api.venuemanagement.model.VenueAddModel;
import com.zhuiyun.project.api.venuemanagement.model.VenueUpdateModel;
import com.zhuiyun.project.api.venuemanagement.service.VenueManagementService;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.constants.CommonConstants;
import com.zhuiyun.project.utils.pageUtil.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import java.text.ParseException;
import java.util.List;

/**
 * @ClassName CoachManagementController
 * @Description TODO
 * @Author wuwan
 * @Date 2023/11/2 13:40
 **/
@RestController
@Api(tags = "场馆管理")
@Slf4j
@RequestMapping("/VenueManagement")
public class VenueManagementController {
    @Autowired
    private VenueManagementService venueManagementService;

    @Resource
    VenueManagementMapper venueManagementMapper;

    /*
     * @Author wuwan
     * @Description 修改场馆信息
     * @Date 2023/11/3 14:09
     * @Return
     */
    @PutMapping("/updateVenue")
    @ApiOperation(value = "修改场馆信息")
    @OptLog(modular = "场馆管理",type = CommonConstants.UPDATE,describe = "修改场馆")
    public CommonResult updateVenue(VenueUpdateModel venueUpdateModel, MultipartFile file) throws CommonException {
        return CommonResult.ok(venueManagementService.updateVenue(venueUpdateModel,file));
    }

    /*
    * @Author wuwan
    * @Description 场馆信息分页查询
    * @Date 2023/11/3 10:09
    * @Return
    */
    @GetMapping("/selectVenue")
    @ApiOperation(value = "场馆信息分页查询")
    @OptLog(modular = "场馆管理",type = CommonConstants.SELECT,describe = "场馆信息分页查询")
    public CommonResult selectVenue(PageRequest pageRequest,String userName,String phone){
        return CommonResult.ok(venueManagementService.selectVenue(pageRequest,userName,phone));
    }
    /*
    * @Author wuwan
    * @Description 场馆封禁
    * @Date 2023/11/6 9:00
    * @Return
    */
    @PutMapping("/changeUserStatus")
    @ApiOperation(value = "场馆封禁")
    @OptLog(modular = "场馆管理",type = CommonConstants.UPDATE,describe = "场馆封禁")
    public CommonResult changeUserStatus(@RequestBody BanRecord banRecord) throws ParseException, MessagingException {
        return CommonResult.ok(venueManagementService.changeUserStatus(banRecord));
    }
    /*
     * @Author wuwan
     * @Description 场馆信息分页查询
     * @Date 2023/11/3 10:09
     * @Return
     */
    @GetMapping("/selectById")
    @ApiOperation(value = "场馆信息分页查询")
    @OptLog(modular = "场馆管理",type = CommonConstants.SELECT,describe = "场馆信息分页查询")
    public CommonResult selectById(PageRequest pageRequest,String id){
        return CommonResult.ok(venueManagementService.selectById(pageRequest,id));
    }

    /*
    * @Author xy
    * @Description todo 查询教练所属场馆
    * @Date 2023/11/29 9:37
    * @Return
    * @param
    */
    @GetMapping("/selectVenueByCoachId")
    @ApiOperation(value = "查询教练所属场馆")
    @OptLog(modular = "场馆管理",type = CommonConstants.SELECT,describe = "查询教练所属场馆")
    public CommonResult selectVenueByCoachId(@RequestParam String venueId){
        QueryWrapper<VenueManagement> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("venue_unique_identifier",venueId);
        List<VenueManagement> venueManagements = venueManagementMapper.selectList(queryWrapper);
        return CommonResult.ok(venueManagements);
    }
    /*
    * @Author wuwan
    * @Description 登录验证
    * @Date 2023/12/7 10:39
    * @Return
    */
}
